/**
 * 简单选择排序，复杂度：O(N x N)
 */
public class SimpleSelectSort {
    public static void main(String[] args) {
        int[] arr = {9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        simpleSelectSort(arr);
        for (int item : arr) {
            System.out.print(item + ",");
        }
    }

    public static void simpleSelectSort(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            int minIndex = i;
            int j = i + 1;
            while (j < arr.length) {
                if (arr[minIndex] > arr[j]) {
                    minIndex = j;
                }
                j++;
            }
            int temp = arr[i];
            arr[i] = arr[minIndex];
            arr[minIndex] = temp;
        }
    }
}
